package com.hama.iotrust.common.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class IndexAction {

    private static final Logger logger = LoggerFactory.getLogger(IndexAction.class);

 
    @RequestMapping(value = "/index")
    public Object handleRequest(HttpServletRequest request) {
        ModelAndView model = new ModelAndView();
        try {
            //UserInfo userInfo = (UserInfo) request.getSession().getAttribute(Constants.LOGIN_USER);
        	Long userId = (Long) request.getAttribute("userId");
        
            if (userId == null) {
            	return "login";
            } else {
                model.addObject("userId", userId);
                model.setViewName("/index");
            }
        } catch (Exception se) {
            model.addObject("exception", se.getMessage());
            model.setViewName("/error");
            logger.error(se.getMessage(), se);
        }
        return model;
    }

}
